Option Explicit

Private Const TEST_TABLE_NAME As String = "table1"
Private Const TEST_POINT As String = "."
Private Const TEST_COL_NAME As String = "col1"
Private Const TEST_SHARE_LINE_COMMENT As String = "--aaaaaa"
Private Const TEST_SINGLE_LINE_COMMENT As String = "--bbbbb"

' ======================================================================
' 执行所有测试用例
' ======================================================================
Public Sub test_all_case()
    ' ==================================================
    ' Public 方法测试
    ' ==================================================
    ' 测试: 设置作用域的类型
    test_ThisClass_setType

    ' ==================================================
    ' ISqlFormatterElem 接口实现测试
    ' ==================================================
    ' 测试: addComponent 方法
    test_ISqlFormatterElem_addComponent
    ' 测试: addComponentToFirst 方法
    test_ISqlFormatterElem_addComponentToFirst
    ' 测试: canAddComponentToFirst 方法
    test_ISqlFormatterElem_canAddComponentToFirst
    ' 测试: getAlignmentElemGroups 方法
    test_ISqlFormatterElem_getAlignmentElemGroups
    ' 测试: setElemNestCount 方法
    test_ISqlFormatterElem_setElemNestCount
    ' 测试: setPrefixSpaceCount 方法
    test_ISqlFormatterElem_setPrefixSpaceCount
    ' 测试: hasBoundaryParenthesis 方法
    test_ISqlFormatterElem_hasBoundaryParenthesis
    ' 测试: addBoundaryLeftParenthesis 方法
    test_ISqlFormatterElem_addBoundaryLeftParenthesis
    ' 测试: addBoundaryRightParenthesis 方法
    test_ISqlFormatterElem_addBoundaryRightParenthesis
    ' 测试: getType 方法
    test_ISqlFormatterElem_getType
    ' 测试: isComment 方法
    test_ISqlFormatterElem_isComment
    ' 测试: isShareLineComment 方法
    test_ISqlFormatterElem_isShareLineComment
    ' 测试: isSingleLineComment 方法
    test_ISqlFormatterElem_isSingleLineComment
    ' 测试: isEndsWithComment 方法
    test_ISqlFormatterElem_isEndsWithComment
    ' 测试: isMultiLine 方法
    test_ISqlFormatterElem_isMultiLine
    ' 测试: toString + toStringArray 方法
    test_ISqlFormatterElem_toString_toStringArray
End Sub


' ======================================================================
' 测试通用处理
' ======================================================================

' 获取一个任意名称的 STR_NAME token
Private Function getStrNameToken(ByRef s As String) As SqlToken
    Set getStrNameToken = New SqlToken
    getStrNameToken.Init s, SqlTokenType.STR_NAME
End Function

' 获取表名 token
Private Function getTableNameToken() As SqlToken
    Set getTableNameToken = New SqlToken
    getTableNameToken.Init TEST_TABLE_NAME, SqlTokenType.STR_NAME
End Function

' 获取 [.] token
Private Function getPointToken() As SqlToken
    Set getPointToken = New SqlToken
    getPointToken.Init TEST_POINT, SqlTokenType.POINT
End Function

' 获取列名 token
Private Function getColNameToken() As SqlToken
    Set getColNameToken = New SqlToken
    getColNameToken.Init TEST_COL_NAME, SqlTokenType.STR_NAME
End Function

' 获取和前一个元素在同一行的注释
Private Function getShareLineCommentToken() As SqlToken
    Set getShareLineCommentToken = New SqlToken
    getShareLineCommentToken.Init TEST_SHARE_LINE_COMMENT, SqlTokenType.SHARE_LINE_COMMENT
End Function

' 获取一个单行的注释
Private Function getSingleLineCommentToken() As SqlToken
    Set getSingleLineCommentToken = New SqlToken
    getSingleLineCommentToken.Init TEST_SINGLE_LINE_COMMENT, SqlTokenType.SINGLE_LINE_COMMENT
End Function

' 获取一个逗号的元素
Private Function getCommaToken() As SqlToken
    Set getCommaToken = New SqlToken
    getCommaToken.Init ",", SqlTokenType.COMMA
End Function

' 获取一个没有边界括号的多行元素
' 多行连接的结果:
' col1 & ","
' col2
Private Function getMultiLineElemNoParenthesis() As ISqlFormatterElem
    Dim g As SqlFormatterCommaDeliMultiElem
    Set g = New SqlFormatterCommaDeliMultiElem

    Dim elem As ISqlFormatterElem
    Set elem = g

    ' 1. 增加一个单行元素
    elem.addComponent getStrNameToken("col1")

    ' 2. 手动设置为多行元素，仍然是单行
    g.setNeedMultiLineWhenHasComma True

    ' 3. 在末尾添加一个逗号元素，仍然是单行的
    elem.addComponent getCommaToken

    ' 4. 再增加一个单行元素，变成多行的
    elem.addComponent getStrNameToken("col2")

    Set getMultiLineElemNoParenthesis = elem
End Function

' 获取一个没有边界括号的多行元素
' 多行连接的结果:
' col1 & ","
' col2 --aaaaaa
Private Function getMultiLineElemNoParenthesisEndWithComment() As ISqlFormatterElem
    Dim g As SqlFormatterCommaDeliMultiElem
    Set g = New SqlFormatterCommaDeliMultiElem

    Dim elem As ISqlFormatterElem
    Set elem = g

    ' 1. 增加一个单行元素
    elem.addComponent getStrNameToken("col1")

    ' 2. 手动设置为多行元素，仍然是单行
    g.setNeedMultiLineWhenHasComma True

    ' 3. 在末尾添加一个逗号元素，仍然是单行的
    elem.addComponent getCommaToken

    ' 4. 再增加一个单行元素，变成多行的
    elem.addComponent getStrNameToken("col2")

    ' 5. 增加一个和前一个元素同一行的注释
    elem.addComponent getShareLineCommentToken

    Set getMultiLineElemNoParenthesisEndWithComment = elem
End Function

' ======================================================================
' Public 方法测试
' ======================================================================
' 测试: 设置作用域的类型
Private Sub test_ThisClass_setType()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterContainerCol
    Set g = New SqlFormatterContainerCol

    ' ==============================
    ' 2. 不设置，默认为: SqlTokenType.NO_MEAN
    ' ==============================
    Debug.Assert g.ISqlFormatterElem_getType = SqlTokenType.NO_MEAN

    ' ==============================
    ' 3. 手动设置
    ' ==============================
    g.setType SqlTokenType.KEY_SELECT
    Debug.Assert g.ISqlFormatterElem_getType = SqlTokenType.KEY_SELECT
End Sub

' ======================================================================
' ISqlFormatterElem 接口实现测试
' ======================================================================
' 测试: addComponent 方法
Private Sub test_ISqlFormatterElem_addComponent()
    Dim config As SqlFormatterConfiguration
    Set config = New SqlFormatterConfiguration

    Dim strArr As IPrimitiveArrayRef

    Dim g As SqlFormatterContainerCol

    ' ==============================
    ' 1. 增加一个单行元素
    ' ==============================
    Set g = New SqlFormatterContainerCol
    g.ISqlFormatterElem_addComponent getTableNameToken

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = TEST_TABLE_NAME

    ' ==============================
    ' 2. 增加第二个单行元素
    ' ==============================
    g.ISqlFormatterElem_addComponent getTableNameToken

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = TEST_TABLE_NAME & " " & TEST_TABLE_NAME

    ' 多行的判断 + 是否注释结尾 的测试不在这里做
End Sub

' 测试: addComponentToFirst 方法
Private Sub test_ISqlFormatterElem_addComponentToFirst()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterContainerCol

    Dim config As SqlFormatterConfiguration
    Set config = New SqlFormatterConfiguration

    Dim strArr As IPrimitiveArrayRef

    ' ==============================
    ' 2. 测试: 增加两个单行元素
    ' ==============================
    Set g = New SqlFormatterContainerCol
    ' 1. 增加两个个单行元素
    g.ISqlFormatterElem_addComponentToFirst getStrNameToken("x1")
    g.ISqlFormatterElem_addComponentToFirst getTableNameToken

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = TEST_TABLE_NAME & " " & "x1"

    ' 2. 检查是单行的
    Debug.Assert g.ISqlFormatterElem_isMultiLine = False
    ' 3. 检查不是以注释结尾
    Debug.Assert g.ISqlFormatterElem_isEndsWithComment = False

    ' ==============================
    ' 3. 测试: 增加一个单行元素 + 一个和前一个元素同一行的注释
    ' ==============================
    Set g = New SqlFormatterContainerCol
    ' 1. 增加后一个注释
    g.ISqlFormatterElem_addComponentToFirst getShareLineCommentToken
    ' 2. 增加前一个单行元素
    g.ISqlFormatterElem_addComponentToFirst getTableNameToken

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = TEST_TABLE_NAME & " " & TEST_SHARE_LINE_COMMENT

    ' 3. 检查是单行的
    Debug.Assert g.ISqlFormatterElem_isMultiLine = False
    ' 4. 检查不是以注释结尾
    Debug.Assert g.ISqlFormatterElem_isEndsWithComment = True

    ' ==============================
    ' 4. 测试: 增加一个和前一个元素同一行的注释 + 一个单行元素
    ' ==============================
    Set g = New SqlFormatterContainerCol
    ' 1. 增加后一个单行元素
    g.ISqlFormatterElem_addComponentToFirst getTableNameToken
    ' 2. 增加前一个注释
    g.ISqlFormatterElem_addComponentToFirst getShareLineCommentToken

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 2
    Debug.Assert strArr.Item(0) = TEST_SHARE_LINE_COMMENT
    Debug.Assert strArr.Item(1) = TEST_TABLE_NAME

    ' 3. 检查是单行的
    Debug.Assert g.ISqlFormatterElem_isMultiLine = True
    ' 4. 检查不是以注释结尾
    Debug.Assert g.ISqlFormatterElem_isEndsWithComment = False

    ' ==============================
    ' 5. 测试: 增加单行元素 + 一个单行注释
    ' ==============================
    Set g = New SqlFormatterContainerCol
    ' 1. 增加后一个注释
    g.ISqlFormatterElem_addComponentToFirst getSingleLineCommentToken
    ' 2. 增加前一个单行元素
    g.ISqlFormatterElem_addComponentToFirst getTableNameToken

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 2
    Debug.Assert strArr.Item(0) = TEST_TABLE_NAME
    Debug.Assert strArr.Item(1) = TEST_SINGLE_LINE_COMMENT

    ' 3. 检查是单行的
    Debug.Assert g.ISqlFormatterElem_isMultiLine = True
    ' 4. 检查不是以注释结尾
    Debug.Assert g.ISqlFormatterElem_isEndsWithComment = True

    ' ==============================
    ' 6. 测试: 增加一个单行注释 + 单行元素
    ' ==============================
    Set g = New SqlFormatterContainerCol
    ' 1. 增加后一个单行元素
    g.ISqlFormatterElem_addComponentToFirst getTableNameToken
    ' 2. 增加前一个注释
    g.ISqlFormatterElem_addComponentToFirst getSingleLineCommentToken

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 2
    Debug.Assert strArr.Item(0) = TEST_SINGLE_LINE_COMMENT
    Debug.Assert strArr.Item(1) = TEST_TABLE_NAME

    ' 3. 检查是单行的
    Debug.Assert g.ISqlFormatterElem_isMultiLine = True
    ' 4. 检查不是以注释结尾
    Debug.Assert g.ISqlFormatterElem_isEndsWithComment = False

    ' ==============================
    ' 7. 测试: 增加一个多行元素
    ' ==============================
    Set g = New SqlFormatterContainerCol
    ' 1. 增加后一个单行元素
    g.ISqlFormatterElem_addComponentToFirst getTableNameToken
    ' 2. 检查是单行的
    Debug.Assert g.ISqlFormatterElem_isMultiLine = False

    ' 3. 增加一个多行元素
    g.ISqlFormatterElem_addComponentToFirst getMultiLineElemNoParenthesis
    ' 4. 检查是多行的
    Debug.Assert g.ISqlFormatterElem_isMultiLine = True

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 2
    Debug.Assert strArr.Item(0) = "col1,"
    Debug.Assert strArr.Item(1) = "col2 " & TEST_TABLE_NAME

    ' 5. 检查不是以注释结尾
    Debug.Assert g.ISqlFormatterElem_isEndsWithComment = False

    ' ==============================
    ' 7. 测试: 增加一个多行且以注释结尾的元素
    ' ==============================
    Set g = New SqlFormatterContainerCol
    ' 1. 增加一个多行且以注释结尾的元素
    g.ISqlFormatterElem_addComponentToFirst getMultiLineElemNoParenthesisEndWithComment
    ' 2. 检查是多行的
    Debug.Assert g.ISqlFormatterElem_isMultiLine = True

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 2
    Debug.Assert strArr.Item(0) = "col1,"
    Debug.Assert strArr.Item(1) = "col2 --aaaaaa"

    ' 5. 检查不是以注释结尾
    Debug.Assert g.ISqlFormatterElem_isEndsWithComment = True

End Sub

' 测试: canAddComponentToFirst 方法
Private Sub test_ISqlFormatterElem_canAddComponentToFirst()
    Dim g As SqlFormatterContainerCol

    ' ==============================
    ' 1. 只增加一个单行元素: True
    ' ==============================
    Set g = New SqlFormatterContainerCol
    g.ISqlFormatterElem_addComponent getTableNameToken
    Debug.Assert g.ISqlFormatterElem_canAddComponentToFirst = True

    ' ==============================
    ' 2. 只增加左边界括号: False
    ' ==============================
    Set g = New SqlFormatterContainerCol
    g.ISqlFormatterElem_addBoundaryLeftParenthesis
    Debug.Assert g.ISqlFormatterElem_canAddComponentToFirst = False

    ' ==============================
    ' 3. 只增加右边界括号: True
    ' ==============================
    Set g = New SqlFormatterContainerCol
    g.ISqlFormatterElem_addBoundaryRightParenthesis
    Debug.Assert g.ISqlFormatterElem_canAddComponentToFirst = True

    ' ==============================
    ' 4. 添加左右边界括号: True
    ' ==============================
    Set g = New SqlFormatterContainerCol
    g.ISqlFormatterElem_addBoundaryLeftParenthesis
    g.ISqlFormatterElem_addBoundaryRightParenthesis
    Debug.Assert g.ISqlFormatterElem_canAddComponentToFirst = False

End Sub

' 测试: getAlignmentElemGroups 方法
Private Sub test_ISqlFormatterElem_getAlignmentElemGroups()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterContainerCol
    Set g = New SqlFormatterContainerCol
    Dim condition As SqlFormatterTwoElemCondition
    Dim condition2 As SqlFormatterTwoElemCondition

    Dim elem As ISqlFormatterElem
    Set elem = g

    Dim groups As IObjArrayRef
    Dim group As IObjArrayRef

    ' ==============================
    ' 2. 在添加元素之前进行检查
    ' ==============================
    Debug.Assert elem.getAlignmentElemGroups Is Nothing

    ' ==============================
    ' 3. 添加第一个单行元素后再检查
    ' ==============================
    elem.addComponent getTableNameToken
    Debug.Assert elem.getAlignmentElemGroups Is Nothing

    ' ==============================
    ' 4. 添加第一个条件对象
    ' ==============================
    Set condition = New SqlFormatterTwoElemCondition
    elem.addComponent condition

    Set groups = elem.getAlignmentElemGroups
    Debug.Assert groups.Count = 1
    Set group = groups.Item(0)
    Debug.Assert group.Count = 1
    Debug.Assert group.Item(0) Is condition

    ' ==============================
    ' 5. 添加第二个条件对象
    ' ==============================
    Set condition2 = New SqlFormatterTwoElemCondition
    elem.addComponent condition2

    Set groups = elem.getAlignmentElemGroups
    Debug.Assert groups.Count = 2
    ' 检查第一个条件
    Set group = groups.Item(0)
    Debug.Assert group.Count = 1
    Debug.Assert group.Item(0) Is condition
    ' 检查第二个条件
    Set group = groups.Item(1)
    Debug.Assert group.Count = 1
    Debug.Assert group.Item(0) Is condition2

    ' ==============================
    ' 6. 添加一个包含多个条件对象的组合对象
    ' ==============================
    ' 创建一个包含多个条件的组合对象
    Dim multiConditions As SqlFormatterCommaDeliMultiElem
    Set multiConditions = New SqlFormatterCommaDeliMultiElem
    Dim condition3 As SqlFormatterTwoElemCondition
    Set condition3 = New SqlFormatterTwoElemCondition
    Dim condition4 As SqlFormatterTwoElemCondition
    Set condition4 = New SqlFormatterTwoElemCondition
    multiConditions.ISqlFormatterElem_addComponent condition3
    multiConditions.ISqlFormatterElem_addComponent condition4

    ' 将这个组合对象保存到 elem
    elem.addComponent multiConditions

    Set groups = elem.getAlignmentElemGroups
    Debug.Assert groups.Count = 4
    ' 检查第一个条件
    Set group = groups.Item(0)
    Debug.Assert group.Count = 1
    Debug.Assert group.Item(0) Is condition
    ' 检查第二个条件
    Set group = groups.Item(1)
    Debug.Assert group.Count = 1
    Debug.Assert group.Item(0) Is condition2
    ' 检查第三个条件
    Set group = groups.Item(2)
    Debug.Assert group.Count = 1
    Debug.Assert group.Item(0) Is condition3
    ' 检查第四个条件
    Set group = groups.Item(3)
    Debug.Assert group.Count = 1
    Debug.Assert group.Item(0) Is condition4

End Sub

' 测试: setElemNestCount 方法
Private Sub test_ISqlFormatterElem_setElemNestCount()
    ' 无法测试
End Sub

' 测试: setPrefixSpaceCount 方法
Private Sub test_ISqlFormatterElem_setPrefixSpaceCount()
    ' 无法测试
End Sub

' 测试: hasBoundaryParenthesis 方法
Private Sub test_ISqlFormatterElem_hasBoundaryParenthesis()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterContainerCol
    Set g = New SqlFormatterContainerCol

    Dim elem As ISqlFormatterElem
    Set elem = g

    ' ==============================
    ' 2. 测试
    ' ==============================
    ' 2. 增加左边界括号
    elem.addBoundaryLeftParenthesis
    Debug.Assert elem.hasBoundaryParenthesis = True

    ' 3. 增加右边界括号
    elem.addBoundaryRightParenthesis
    Debug.Assert elem.hasBoundaryParenthesis = True

    ' 4. 重新创建对象，并只添加右边界括号
    Set g = New SqlFormatterContainerCol
    Set elem = g

    elem.addComponent getTableNameToken
    Debug.Assert elem.hasBoundaryParenthesis = False

    '    增加右边界括号
    elem.addBoundaryRightParenthesis
    Debug.Assert elem.hasBoundaryParenthesis = True
End Sub

' 测试: addBoundaryLeftParenthesis 方法
Private Sub test_ISqlFormatterElem_addBoundaryLeftParenthesis()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterContainerCol
    Set g = New SqlFormatterContainerCol

    Dim elem As ISqlFormatterElem
    Set elem = g

    Dim config As SqlFormatterConfiguration
    Set config = New SqlFormatterConfiguration

    Dim strArr As IPrimitiveArrayRef

    ' ==============================
    ' 2. 添加一个元素
    ' ==============================
    elem.addComponent getTableNameToken
    Debug.Assert elem.toString(config) = TEST_TABLE_NAME

    ' ==============================
    ' 3. 添加一个左括号
    ' ==============================
    elem.addBoundaryLeftParenthesis
    Debug.Assert elem.toString(config) = "(" & TEST_TABLE_NAME

    Set strArr = elem.toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = "(" & TEST_TABLE_NAME

    ' ==============================
    ' 4. 添加多个左括号
    ' ==============================
    elem.addBoundaryLeftParenthesis(3)
    Debug.Assert elem.toString(config) = "((((" & TEST_TABLE_NAME

    Set strArr = elem.toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = "((((" & TEST_TABLE_NAME
End Sub

' 测试: addBoundaryRightParenthesis 方法
Private Sub test_ISqlFormatterElem_addBoundaryRightParenthesis()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterContainerCol
    Set g = New SqlFormatterContainerCol

    Dim elem As ISqlFormatterElem
    Set elem = g

    Dim config As SqlFormatterConfiguration
    Set config = New SqlFormatterConfiguration

    Dim strArr As IPrimitiveArrayRef

    ' ==============================
    ' 2. 添加一个元素
    ' ==============================
    elem.addComponent getTableNameToken
    Debug.Assert elem.toString(config) = TEST_TABLE_NAME

    ' ==============================
    ' 3. 添加一个右括号
    ' ==============================
    elem.addBoundaryRightParenthesis
    Debug.Assert elem.toString(config) = TEST_TABLE_NAME & ")"

    Set strArr = elem.toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = TEST_TABLE_NAME & ")"

    ' ==============================
    ' 4. 添加多个右括号
    ' ==============================
    elem.addBoundaryRightParenthesis(3)
    Debug.Assert elem.toString(config) = TEST_TABLE_NAME & "))))"

    Set strArr = elem.toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = TEST_TABLE_NAME & "))))"
End Sub

' 测试: getType 方法
Private Sub test_ISqlFormatterElem_getType()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterContainerCol
    Set g = New SqlFormatterContainerCol

    ' ==============================
    ' 2. 默认没有类型
    ' ==============================
    Debug.Assert g.ISqlFormatterElem_getType = SqlTokenType.NO_MEAN

    ' ==============================
    ' 3. 手动设置类型
    ' ==============================
    g.setType SqlTokenType.KEY_SELECT
    Debug.Assert g.ISqlFormatterElem_getType = SqlTokenType.KEY_SELECT
End Sub

' 测试: isComment 方法
Private Sub test_ISqlFormatterElem_isComment()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterContainerCol
    Set g = New SqlFormatterContainerCol

    Dim elem As ISqlFormatterElem
    Set elem = g
    ' ==============================
    ' 2. 默认为 false
    ' ==============================
    Debug.Assert elem.isComment = False

    ' ==============================
    ' 3. 即使添加一个注释，也是 false
    ' ==============================
    elem.addComponent getShareLineCommentToken
    Debug.Assert elem.isComment = False

    elem.addComponent getSingleLineCommentToken
    Debug.Assert elem.isComment = False
End Sub

' 测试: isShareLineComment 方法
Private Sub test_ISqlFormatterElem_isShareLineComment()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterContainerCol
    Set g = New SqlFormatterContainerCol

    Dim elem As ISqlFormatterElem
    Set elem = g

    ' ==============================
    ' 2. 默认为 false
    ' ==============================
    Debug.Assert elem.isShareLineComment = False

    ' ==============================
    ' 3. 即使添加一个注释，也是 false
    ' ==============================
    elem.addComponent getShareLineCommentToken
    Debug.Assert elem.isShareLineComment = False

    elem.addComponent getSingleLineCommentToken
    Debug.Assert elem.isShareLineComment = False
End Sub

' 测试: isSingleLineComment 方法
Private Sub test_ISqlFormatterElem_isSingleLineComment()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterContainerCol
    Set g = New SqlFormatterContainerCol

    Dim elem As ISqlFormatterElem
    Set elem = g

    ' ==============================
    ' 2. 默认为 false
    ' ==============================
    Debug.Assert elem.isShareLineComment = False

    ' ==============================
    ' 3. 即使添加一个注释，也是 false
    ' ==============================
    elem.addComponent getShareLineCommentToken
    Debug.Assert elem.isSingleLineComment = False

    elem.addComponent getSingleLineCommentToken
    Debug.Assert elem.isSingleLineComment = False
End Sub

' 测试: isEndsWithComment 方法
Private Sub test_ISqlFormatterElem_isEndsWithComment()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterContainerCol
    Set g = New SqlFormatterContainerCol

    Dim elem As ISqlFormatterElem
    Set elem = g

    ' ==============================
    ' 2. 默认为 false
    ' ==============================
    Debug.Assert elem.isEndsWithComment = False

    ' ==============================
    ' 3. 测试
    ' ==============================
    ' 1. 添加一个元素
    elem.addComponent getTableNameToken
    Debug.Assert elem.isEndsWithComment = False

    ' 2. 添加一个和前一个元素同一行的注释
    elem.addComponent getShareLineCommentToken
    Debug.Assert elem.isEndsWithComment = True

    ' 3. 再添加一个非注释元素
    elem.addComponent getTableNameToken
    Debug.Assert elem.isEndsWithComment = False

    ' 4. 添加一个单行注释
    elem.addComponent getSingleLineCommentToken
    Debug.Assert elem.isEndsWithComment = True

    ' 5. 添加左括号 --> 仍然是以注释结尾的
    elem.addBoundaryLeftParenthesis
    Debug.Assert elem.isEndsWithComment = True

    ' 6. 添加右括号 --> 不是以注释结尾的
    elem.addBoundaryRightParenthesis
    Debug.Assert elem.isEndsWithComment = False
End Sub

' 测试: isMultiLine 方法
Private Sub test_ISqlFormatterElem_isMultiLine()
    Dim g As SqlFormatterContainerCol

    ' ==============================
    ' 1. 增加一个单行元素: False
    ' ==============================
    Set g = New SqlFormatterContainerCol
    g.ISqlFormatterElem_addComponent getTableNameToken
    Debug.Assert g.ISqlFormatterElem_isMultiLine = False

    ' ==============================
    ' 2. 增加一个多行元素: True
    ' ==============================
    g.ISqlFormatterElem_addComponent getMultiLineElemNoParenthesisEndWithComment
    Debug.Assert g.ISqlFormatterElem_isMultiLine = True
    
    ' ==============================
    ' 3. 增加单行元素 + 一个和前一个元素同一行的注释: False
    ' ==============================
    Set g = New SqlFormatterContainerCol
    g.ISqlFormatterElem_addComponent getTableNameToken
    g.ISqlFormatterElem_addComponent getShareLineCommentToken
    Debug.Assert g.ISqlFormatterElem_isMultiLine = False

    ' ==============================
    ' 4. 增加单行元素 + 一个和前一个元素同一行的注释 + 左边界括号: True
    ' ==============================
    Set g = New SqlFormatterContainerCol
    g.ISqlFormatterElem_addComponent getTableNameToken
    g.ISqlFormatterElem_addComponent getShareLineCommentToken
    g.ISqlFormatterElem_addBoundaryLeftParenthesis
    Debug.Assert g.ISqlFormatterElem_isMultiLine = True

    ' ==============================
    ' 5. 增加单行元素 + 一个和前一个元素同一行的注释 + 右边界括号: True
    ' ==============================
    Set g = New SqlFormatterContainerCol
    g.ISqlFormatterElem_addComponent getTableNameToken
    g.ISqlFormatterElem_addComponent getShareLineCommentToken
    g.ISqlFormatterElem_addBoundaryRightParenthesis
    Debug.Assert g.ISqlFormatterElem_isMultiLine = True

    ' ==============================
    ' 6. 增加单行元素 + 一个和前一个元素同一行的注释 + 左右边界括号: True
    ' ==============================
    Set g = New SqlFormatterContainerCol
    g.ISqlFormatterElem_addComponent getTableNameToken
    g.ISqlFormatterElem_addComponent getShareLineCommentToken
    g.ISqlFormatterElem_addBoundaryLeftParenthesis
    g.ISqlFormatterElem_addBoundaryRightParenthesis
    Debug.Assert g.ISqlFormatterElem_isMultiLine = True
    
End Sub

' 测试: toString + toStringArray 方法
Private Sub test_ISqlFormatterElem_toString_toStringArray()
    ' ==============================
    ' 1. 初始化
    ' ==============================
    Dim g As SqlFormatterContainerCol
    Set g = New SqlFormatterContainerCol

    Dim elem As ISqlFormatterElem
    Set elem = g

    Dim config As SqlFormatterConfiguration
    Set config = New SqlFormatterConfiguration

    Dim strArr As IPrimitiveArrayRef

    ' ==============================
    ' 2. 添加第一个单行元素
    ' ==============================
    elem.addComponent getTableNameToken
    Debug.Assert elem.toString(config) = TEST_TABLE_NAME

    Set strArr = elem.toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = TEST_TABLE_NAME

    ' ==============================
    ' 3. 添加第二个单行元素
    ' ==============================
    elem.addComponent getColNameToken
    Debug.Assert elem.toString(config) = TEST_TABLE_NAME & " " & TEST_COL_NAME

    Set strArr = elem.toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = TEST_TABLE_NAME & " " & TEST_COL_NAME

    ' ==============================
    ' 4. 添加一个逗号
    ' ==============================
    elem.addComponent getCommaToken
    Debug.Assert elem.toString(config) = TEST_TABLE_NAME & " " & TEST_COL_NAME & ","

    Set strArr = elem.toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = TEST_TABLE_NAME & " " & TEST_COL_NAME & ","

    ' ==============================
    ' 5. 添加第三个单行元素
    ' ==============================
    elem.addComponent getColNameToken
    Debug.Assert elem.toString(config) = TEST_TABLE_NAME & " " & TEST_COL_NAME & ", " & TEST_COL_NAME

    Set strArr = elem.toStringArray(config)
    Debug.Assert strArr.Count = 1
    Debug.Assert strArr.Item(0) = TEST_TABLE_NAME & " " & TEST_COL_NAME & ", " & TEST_COL_NAME

    ' ==============================
    ' 6. 添加边界括号
    ' ==============================
    elem.addBoundaryLeftParenthesis(2)
    elem.addBoundaryRightParenthesis(2)

    Debug.Assert elem.toString(config) = "((" & TEST_TABLE_NAME & " " & TEST_COL_NAME & ", " & TEST_COL_NAME & "))"

    ' ==============================
    ' 7. 添加一个多行的元素，默认变为多行的
    ' ==============================
    elem.addComponent getMultiLineElemNoParenthesis

    ' 将边界括号去掉
    elem.addBoundaryLeftParenthesis(-2)
    elem.addBoundaryRightParenthesis(-2)

    Debug.Assert elem.toString(config) = TEST_TABLE_NAME & " " & TEST_COL_NAME & ", " & TEST_COL_NAME & " col1," & vbCrLf & _
                                         "col2"

    Set strArr = elem.toStringArray(config)
    Debug.Assert strArr.Count = 2
    Debug.Assert strArr.Item(0) = TEST_TABLE_NAME & " " & TEST_COL_NAME & ", " & TEST_COL_NAME & " col1,"
    Debug.Assert strArr.Item(1) = "col2"

    ' ==============================
    ' 8. 单行元素 + 注释结尾 + 边界括号
    ' ==============================
    Set g = New SqlFormatterContainerCol
    Set elem = g

    ' 添加单行元素
    elem.addComponent getTableNameToken
    ' 注释结尾
    elem.addComponent getShareLineCommentToken
    ' 添加边界括号
    elem.addBoundaryLeftParenthesis(3)

    Set strArr = elem.toStringArray(config)
    Debug.Assert strArr.Count = 2
    Debug.Assert strArr.Item(0) = "((("
    Debug.Assert strArr.Item(1) = "    " & TEST_TABLE_NAME & " --aaaaaa"

    ' ==============================
    ' 9. 特殊case: 左括号 + 一个同行注释 + 一个元素
    ' ==============================
    Set g = New SqlFormatterContainerCol

    ' 1. 添加一个和前一个元素同一行的注释
    g.ISqlFormatterElem_addComponent getShareLineCommentToken
    ' 2. 添加多个单行元素
    g.ISqlFormatterElem_addComponent getStrNameToken("x1")
    ' 3. 设置边界括号: 左边界括号
    g.ISqlFormatterElem_addBoundaryLeftParenthesis

    Set strArr = g.ISqlFormatterElem_toStringArray(config)
    Debug.Assert strArr.Count = 2
    Debug.Assert strArr.Item(0) = "( --aaaaaa"
    Debug.Assert strArr.Item(1) = "    x1"
End Sub